#include "server.h"

void openAccount(char* buf)
{
	//获取银行卡号
	sprintf(ctos.acc.bank,"%d",createCardNo(BANK_PATH));

	//设置初始密码
	sprintf(ctos.acc.password,"123456");

	//设置锁定状态
	ctos.acc.isLock = 0;

	char path[PATH_LEN] = {};
	sprintf(path,"%s%s",ACC_PATH,ctos.acc.bank);

	int fd = open(path,O_WRONLY|O_CREAT|O_EXCL,0644);
	if(0 > fd)
	{
		error("open");
		sprintf(buf,"N:服务器正在升级，开户失败!");
		return;
	}

	write(fd,&ctos.acc,sizeof(ctos.acc));
	sprintf(buf,"Y:开户成功，卡号:%s 密码:%s",ctos.acc.bank,ctos.acc.password);
	close(fd);
}